/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSkyRoom;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import ru.jSkyRoom.interfaces.JSkyMod;
import ru.jSkyRoom.interfaces.major.Major;
import skyproc.FormID;
import skyproc.GRUP_TYPE;

/**
 *
 * @author Rakev
 */
public class CompositeMod implements JSkyMod {

    private Collection<JSkyMod> mods;

    public CompositeMod(Collection<JSkyMod> mods) {
        this.mods = mods;
    }

    @Override
    public void addMajor(Major major) {
        throw new UnsupportedOperationException("Not supported.");
    }

    @Override
    public void removeMajor(Major major) {
        throw new UnsupportedOperationException("Not supported.");
    }

    @Override
    public Major makeCopy(Major template, String newEDID) {
        throw new UnsupportedOperationException("Not supported.");
    }

    @Override
    public void addAsOverrides(JSkyMod mod, GRUP_TYPE... grupTypes) {
        throw new UnsupportedOperationException("Not supported.");
    }

    @Override
    public Major getMajor(FormID id, GRUP_TYPE... lookingGrups) {
        for (JSkyMod mod : mods) {
            Major finded = mod.getMajor(id, lookingGrups);
            if (finded != null) {
                return finded;
            }
        }
        return null;
    }

    @Override
    public Major getMajor(String editId, GRUP_TYPE... lookingGrups) {
        for (JSkyMod mod : mods) {
            Major finded = mod.getMajor(editId, lookingGrups);
            if (finded != null) {
                return finded;
            }
        }
        return null;
    }

    @Override
    public boolean contains(Major major) {
        for (JSkyMod mod : mods) {
            if (mod.contains(major)) {
                return true;
            }
        }
        return false;
    }

    @Override
    public Collection<Major> getMajors(GRUP_TYPE grupType) {
        Set<Major> majors = new HashSet<>();
        for (JSkyMod mod : mods) {
            majors.addAll(mod.getMajors(grupType));
        }
        return majors;
    }

    @Override
    public String getName() {
        return mods.toString();
    }
}
